package com.mpp.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mpp.admin.entity.PageEntity;
import com.mpp.admin.entity.SysRole;
import com.mpp.admin.service.SysRoleService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;;

/**
 * @author mapp
 * @des 角色
 * @date 2019-3-15 13:53:11
 */
@Controller
@RequestMapping("/sysRole")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @RequestMapping("/index")
    public String index() {
        return "sysRole";
    }

    @RequestMapping("/getAll")
    @ResponseBody
    public PageEntity getAll(Integer page, Integer limit, SysRole sysRole) {

        QueryWrapper wrapper = new QueryWrapper();
        // 查询条件
        String rolename = sysRole.getRolename();
        wrapper.like(StringUtils.isNotBlank(rolename), "rolename", rolename);
        String status = sysRole.getStatus();
        wrapper.eq(StringUtils.isNotBlank(status), "status", status);
        return (PageEntity) sysRoleService.page(PageEntity.build(page, limit), wrapper);
    }
}
